From 8784f2296434639697c105f9c71a1e0fe42cf589 Mon Sep 17 00:00:00 2001 From: Chad Horohoe Date: Wed, 5 Nov 2014 11:03:20 -0800 Subject: [PATCH] Profiling: remove "m" prefixes from variables since they're pointless Change-Id: I88cdbac935d6d908fa3745634922a0bb70c0dbc8 --- includes/profiler/Profiler.php | 14 +-- includes/profiler/ProfilerSimpleDB.php | 2 +- includes/profiler/ProfilerSimpleText.php | 10 +- includes/profiler/ProfilerSimpleTrace.php | 8 +- includes/profiler/ProfilerSimpleUDP.php | 2 +- includes/profiler/ProfilerStandard.php | 108 +++++++++++----------- includes/profiler/TransactionProfiler.php | 34 +++---- 7 files changed, 89 insertions(+), 89 deletions(-) diff --git a/includes/profiler/Profiler.php b/includes/profiler/Profiler.php index 46296917cc..18bd430e39 100644 --- a/includes/profiler/Profiler.php +++ b/includes/profiler/Profiler.php @@ -30,9 +30,9 @@ */ abstract class Profiler { /** @var string|bool Profiler ID for bucketing data */ - protected $mProfileID = false; + protected $profileID = false; /** @var bool Whether MediaWiki is in a SkinTemplate output context */ - protected $mTemplated = false; + protected $templated = false; /** @var TransactionProfiler */ protected $trxProfiler; @@ -47,7 +47,7 @@ abstract class Profiler { */ public function __construct( array $params ) { if ( isset( $params['profileID'] ) ) { - $this->mProfileID = $params['profileID']; + $this->profileID = $params['profileID']; } $this->trxProfiler = new TransactionProfiler(); } @@ -96,17 +96,17 @@ abstract class Profiler { * @param string $id */ public function setProfileID( $id ) { - $this->mProfileID = $id; + $this->profileID = $id; } /** * @return string */ public function getProfileID() { - if ( $this->mProfileID === false ) { + if ( $this->profileID === false ) { return wfWikiID(); } else { - return $this->mProfileID; + return $this->profileID; } } @@ -148,7 +148,7 @@ abstract class Profiler { * @param bool $t */ public function setTemplated( $t ) { - $this->mTemplated = $t; + $this->templated = $t; } /** diff --git a/includes/profiler/ProfilerSimpleDB.php b/includes/profiler/ProfilerSimpleDB.php index 5e62f7c8b4..3625db630d 100644 --- a/includes/profiler/ProfilerSimpleDB.php +++ b/includes/profiler/ProfilerSimpleDB.php @@ -56,7 +56,7 @@ class ProfilerSimpleDB extends ProfilerStandard { if ( $useTrx ) { $dbw->startAtomic( __METHOD__ ); } - foreach ( $this->mCollated as $name => $data ) { + foreach ( $this->collated as $name => $data ) { $eventCount = $data['count']; $timeSum = (float)( $data['real'] * 1000 ); $memorySum = (float)$data['memory']; diff --git a/includes/profiler/ProfilerSimpleText.php b/includes/profiler/ProfilerSimpleText.php index d020d1ff20..264845e291 100644 --- a/includes/profiler/ProfilerSimpleText.php +++ b/includes/profiler/ProfilerSimpleText.php @@ -43,18 +43,18 @@ class ProfilerSimpleText extends ProfilerStandard { public function logData() { $out = ''; - if ( $this->mTemplated ) { + if ( $this->templated ) { $this->close(); - $totalReal = isset( $this->mCollated['-total'] ) - ? $this->mCollated['-total']['real'] + $totalReal = isset( $this->collated['-total'] ) + ? $this->collated['-total']['real'] : 0; // profiling mismatch error? - uasort( $this->mCollated, function( $a, $b ) { + uasort( $this->collated, function( $a, $b ) { // sort descending by time elapsed return $a['real'] < $b['real']; } ); - array_walk( $this->mCollated, + array_walk( $this->collated, function( $item, $key ) use ( &$out, $totalReal ) { $perc = $totalReal ? $item['real'] / $totalReal * 100 : 0; $out .= sprintf( "%6.2f%% %3.6f %6d - %s\n", diff --git a/includes/profiler/ProfilerSimpleTrace.php b/includes/profiler/ProfilerSimpleTrace.php index 0dd406798d..893d9605a2 100644 --- a/includes/profiler/ProfilerSimpleTrace.php +++ b/includes/profiler/ProfilerSimpleTrace.php @@ -34,11 +34,11 @@ class ProfilerSimpleTrace extends ProfilerStandard { parent::profileIn( $functionname ); $this->trace .= " " . sprintf( "%6.1f", $this->memoryDiff() ) . - str_repeat( " ", count( $this->mWorkStack ) ) . " > " . $functionname . "\n"; + str_repeat( " ", count( $this->workStack ) ) . " > " . $functionname . "\n"; } public function profileOut( $functionname ) { - $item = end( $this->mWorkStack ); + $item = end( $this->workStack ); parent::profileOut( $functionname ); @@ -55,7 +55,7 @@ class ProfilerSimpleTrace extends ProfilerStandard { } $elapsedreal = $this->getTime() - $ortime; $this->trace .= sprintf( "%03.6f %6.1f", $elapsedreal, $this->memoryDiff() ) . - str_repeat( " ", count( $this->mWorkStack ) + 1 ) . " < " . $functionname . "\n"; + str_repeat( " ", count( $this->workStack ) + 1 ) . " < " . $functionname . "\n"; } } @@ -66,7 +66,7 @@ class ProfilerSimpleTrace extends ProfilerStandard { } public function logData() { - if ( $this->mTemplated ) { + if ( $this->templated ) { $contentType = $this->getContentType(); if ( PHP_SAPI === 'cli' ) { print ""; diff --git a/includes/profiler/ProfilerSimpleUDP.php b/includes/profiler/ProfilerSimpleUDP.php index 02405afc98..2671376a69 100644 --- a/includes/profiler/ProfilerSimpleUDP.php +++ b/includes/profiler/ProfilerSimpleUDP.php @@ -45,7 +45,7 @@ class ProfilerSimpleUDP extends ProfilerStandard { $sock = socket_create( AF_INET, SOCK_DGRAM, SOL_UDP ); $plength = 0; $packet = ""; - foreach ( $this->mCollated as $entry => $pfdata ) { + foreach ( $this->collated as $entry => $pfdata ) { if ( !isset( $pfdata['count'] ) || !isset( $pfdata['cpu'] ) || !isset( $pfdata['cpu_sq'] ) diff --git a/includes/profiler/ProfilerStandard.php b/includes/profiler/ProfilerStandard.php index ea13bfb748..2dcb00ab45 100644 --- a/includes/profiler/ProfilerStandard.php +++ b/includes/profiler/ProfilerStandard.php @@ -32,18 +32,18 @@ */ class ProfilerStandard extends Profiler { /** @var array List of resolved profile calls with start/end data */ - protected $mStack = array(); + protected $stack = array(); /** @var array Queue of open profile calls with start data */ - protected $mWorkStack = array(); + protected $workStack = array(); /** @var array Map of (function name => aggregate data array) */ - protected $mCollated = array(); + protected $collated = array(); /** @var bool */ - protected $mCollateDone = false; + protected $collateDone = false; /** @var bool Whether to collect the full stack trace or just aggregates */ - protected $mCollateOnly = true; + protected $collateOnly = true; /** @var array Cache of a standard broken collation entry */ - protected $mErrorEntry; + protected $errorEntry; /** * @param array $params @@ -77,17 +77,17 @@ class ProfilerStandard extends Profiler { * Add the inital item in the stack. */ protected function addInitialStack() { - $this->mErrorEntry = $this->getErrorEntry(); + $this->errorEntry = $this->getErrorEntry(); $initialTime = $this->getInitialTime( 'wall' ); $initialCpu = $this->getInitialTime( 'cpu' ); if ( $initialTime !== null && $initialCpu !== null ) { - $this->mWorkStack[] = array( '-total', 0, $initialTime, $initialCpu, 0 ); - if ( $this->mCollateOnly ) { - $this->mWorkStack[] = array( '-setup', 1, $initialTime, $initialCpu, 0 ); + $this->workStack[] = array( '-total', 0, $initialTime, $initialCpu, 0 ); + if ( $this->collateOnly ) { + $this->workStack[] = array( '-setup', 1, $initialTime, $initialCpu, 0 ); $this->profileOut( '-setup' ); } else { - $this->mStack[] = array( '-setup', 1, $initialTime, $initialCpu, 0, + $this->stack[] = array( '-setup', 1, $initialTime, $initialCpu, 0, $this->getTime( 'wall' ), $this->getTime( 'cpu' ), 0 ); } } else { @@ -110,8 +110,8 @@ class ProfilerStandard extends Profiler { 'max_cpu' => 0.0, 'min_real' => 0.0, 'max_real' => 0.0, - 'periods' => array(), // not filled if mCollateOnly - 'overhead' => 0 // not filled if mCollateOnly + 'periods' => array(), // not filled if collateOnly + 'overhead' => 0 // not filled if collateOnly ); } @@ -137,10 +137,10 @@ class ProfilerStandard extends Profiler { protected function updateEntry( $name, $elapsedCpu, $elapsedReal, $memChange, $subcalls = 0, $period = null ) { - $entry =& $this->mCollated[$name]; + $entry =& $this->collated[$name]; if ( !is_array( $entry ) ) { $entry = $this->getZeroEntry(); - $this->mCollated[$name] =& $entry; + $this->collated[$name] =& $entry; } $entry['cpu'] += $elapsedCpu; $entry['cpu_sq'] += $elapsedCpu * $elapsedCpu; @@ -168,13 +168,13 @@ class ProfilerStandard extends Profiler { global $wgDebugFunctionEntry; if ( $wgDebugFunctionEntry ) { - $this->debug( str_repeat( ' ', count( $this->mWorkStack ) ) . + $this->debug( str_repeat( ' ', count( $this->workStack ) ) . 'Entering ' . $functionname . "\n" ); } - $this->mWorkStack[] = array( + $this->workStack[] = array( $functionname, - count( $this->mWorkStack ), + count( $this->workStack ), $this->getTime( 'time' ), $this->getTime( 'cpu' ), memory_get_usage() @@ -190,11 +190,11 @@ class ProfilerStandard extends Profiler { global $wgDebugFunctionEntry; if ( $wgDebugFunctionEntry ) { - $this->debug( str_repeat( ' ', count( $this->mWorkStack ) - 1 ) . + $this->debug( str_repeat( ' ', count( $this->workStack ) - 1 ) . 'Exiting ' . $functionname . "\n" ); } - $item = array_pop( $this->mWorkStack ); + $item = array_pop( $this->workStack ); list( $ofname, /* $ocount */, $ortime, $octime, $omem ) = $item; if ( $item === null ) { @@ -204,31 +204,31 @@ class ProfilerStandard extends Profiler { if ( $ofname !== '-total' ) { $message = "Profile section ended by close(): {$ofname}"; $this->debugGroup( 'profileerror', $message ); - if ( $this->mCollateOnly ) { - $this->mCollated[$message] = $this->mErrorEntry; + if ( $this->collateOnly ) { + $this->collated[$message] = $this->errorEntry; } else { - $this->mStack[] = array( $message, 0, 0.0, 0.0, 0, 0.0, 0.0, 0 ); + $this->stack[] = array( $message, 0, 0.0, 0.0, 0, 0.0, 0.0, 0 ); } } $functionname = $ofname; } elseif ( $ofname !== $functionname ) { $message = "Profiling error: in({$ofname}), out($functionname)"; $this->debugGroup( 'profileerror', $message ); - if ( $this->mCollateOnly ) { - $this->mCollated[$message] = $this->mErrorEntry; + if ( $this->collateOnly ) { + $this->collated[$message] = $this->errorEntry; } else { - $this->mStack[] = array( $message, 0, 0.0, 0.0, 0, 0.0, 0.0, 0 ); + $this->stack[] = array( $message, 0, 0.0, 0.0, 0, 0.0, 0.0, 0 ); } } $realTime = $this->getTime( 'wall' ); $cpuTime = $this->getTime( 'cpu' ); - if ( $this->mCollateOnly ) { + if ( $this->collateOnly ) { $elapsedcpu = $cpuTime - $octime; $elapsedreal = $realTime - $ortime; $memchange = memory_get_usage() - $omem; $this->updateEntry( $functionname, $elapsedcpu, $elapsedreal, $memchange ); } else { - $this->mStack[] = array_merge( $item, + $this->stack[] = array_merge( $item, array( $realTime, $cpuTime, memory_get_usage() ) ); } } @@ -238,7 +238,7 @@ class ProfilerStandard extends Profiler { * Close opened profiling sections */ public function close() { - while ( count( $this->mWorkStack ) ) { + while ( count( $this->workStack ) ) { $this->profileOut( 'close' ); } } @@ -260,7 +260,7 @@ class ProfilerStandard extends Profiler { $wgDebugFunctionEntry = false; // hack - if ( !count( $this->mStack ) && !count( $this->mCollated ) ) { + if ( !count( $this->stack ) && !count( $this->collated ) ) { return "No profiling output\n"; } @@ -277,7 +277,7 @@ class ProfilerStandard extends Profiler { */ protected function getCallTree() { return implode( '', array_map( - array( &$this, 'getCallTreeLine' ), $this->remapCallTree( $this->mStack ) + array( &$this, 'getCallTreeLine' ), $this->remapCallTree( $this->stack ) ) ); } @@ -338,28 +338,28 @@ class ProfilerStandard extends Profiler { } /** - * Populate mCollated + * Populate collated */ protected function collateData() { - if ( $this->mCollateDone ) { + if ( $this->collateDone ) { return; } - $this->mCollateDone = true; + $this->collateDone = true; $this->close(); // set "-total" entry - if ( $this->mCollateOnly ) { + if ( $this->collateOnly ) { return; // already collated as methods exited } - $this->mCollated = array(); + $this->collated = array(); # Estimate profiling overhead - $profileCount = count( $this->mStack ); + $profileCount = count( $this->stack ); self::calculateOverhead( $profileCount ); # First, subtract the overhead! $overheadTotal = $overheadMemory = $overheadInternal = array(); - foreach ( $this->mStack as $entry ) { + foreach ( $this->stack as $entry ) { // $entry is (name,pos,rtime0,cputime0,mem0,rtime1,cputime1,mem1) $fname = $entry[0]; $elapsed = $entry[5] - $entry[2]; @@ -380,13 +380,13 @@ class ProfilerStandard extends Profiler { array_sum( $overheadInternal ) / count( $overheadInternal ) : 0; # Collate - foreach ( $this->mStack as $index => $entry ) { + foreach ( $this->stack as $index => $entry ) { // $entry is (name,pos,rtime0,cputime0,mem0,rtime1,cputime1,mem1) $fname = $entry[0]; $elapsedCpu = $entry[6] - $entry[3]; $elapsedReal = $entry[5] - $entry[2]; $memchange = $entry[7] - $entry[4]; - $subcalls = $this->calltreeCount( $this->mStack, $index ); + $subcalls = $this->calltreeCount( $this->stack, $index ); if ( substr( $fname, 0, 9 ) !== '-overhead' ) { # Adjust for profiling overhead (except special values with elapsed=0 @@ -402,8 +402,8 @@ class ProfilerStandard extends Profiler { $this->updateEntry( $fname, $elapsedCpu, $elapsedReal, $memchange, $subcalls, $period ); } - $this->mCollated['-overhead-total']['count'] = $profileCount; - arsort( $this->mCollated, SORT_NUMERIC ); + $this->collated['-overhead-total']['count'] = $profileCount; + arsort( $this->collated, SORT_NUMERIC ); } /** @@ -421,11 +421,11 @@ class ProfilerStandard extends Profiler { $prof = "\nProfiling data\n"; $prof .= sprintf( $titleFormat, 'Name', 'Calls', 'Total', 'Each', '%', 'Mem' ); - $total = isset( $this->mCollated['-total'] ) - ? $this->mCollated['-total']['real'] + $total = isset( $this->collated['-total'] ) + ? $this->collated['-total']['real'] : 0; - foreach ( $this->mCollated as $fname => $data ) { + foreach ( $this->collated as $fname => $data ) { $calls = $data['count']; $percent = $total ? 100 * $data['real'] / $total : 0; $memory = $data['memory']; @@ -454,28 +454,28 @@ class ProfilerStandard extends Profiler { // If some outer methods have not yet called wfProfileOut(), work around // that by clearing anything in the work stack to just the "-total" entry. // Collate after doing this so the results do not include profile errors. - if ( count( $this->mWorkStack ) > 1 ) { - $oldWorkStack = $this->mWorkStack; - $this->mWorkStack = array( $this->mWorkStack[0] ); // just the "-total" one + if ( count( $this->workStack ) > 1 ) { + $oldWorkStack = $this->workStack; + $this->workStack = array( $this->workStack[0] ); // just the "-total" one } else { $oldWorkStack = null; } $this->collateData(); // If this trick is used, then the old work stack is swapped back afterwards - // and mCollateDone is reset to false. This means that logData() will still + // and collateDone is reset to false. This means that logData() will still // make use of all the method data since the missing wfProfileOut() calls // should be made by the time it is called. if ( $oldWorkStack ) { - $this->mWorkStack = $oldWorkStack; - $this->mCollateDone = false; + $this->workStack = $oldWorkStack; + $this->collateDone = false; } - $total = isset( $this->mCollated['-total'] ) - ? $this->mCollated['-total']['real'] + $total = isset( $this->collated['-total'] ) + ? $this->collated['-total']['real'] : 0; $profile = array(); - foreach ( $this->mCollated as $fname => $data ) { + foreach ( $this->collated as $fname => $data ) { $periods = array(); foreach ( $data['periods'] as $period ) { $period['start'] *= 1000; diff --git a/includes/profiler/TransactionProfiler.php b/includes/profiler/TransactionProfiler.php index 91b7bb7d5c..7843ac18f1 100644 --- a/includes/profiler/TransactionProfiler.php +++ b/includes/profiler/TransactionProfiler.php @@ -32,11 +32,11 @@ */ class TransactionProfiler { /** @var float Seconds */ - protected $mDBLockThreshold = 3.0; + protected $dbLockThreshold = 3.0; /** @var array DB/server name => (active trx count, time, DBs involved) */ - protected $mDBTrxHoldingLocks = array(); + protected $dbTrxHoldingLocks = array(); /** @var array DB/server name => list of (function name, elapsed time) */ - protected $mDBTrxMethodTimes = array(); + protected $dbTrxMethodTimes = array(); /** * Mark a DB as in a transaction with one or more writes pending @@ -49,16 +49,16 @@ class TransactionProfiler { */ public function transactionWritingIn( $server, $db, $id ) { $name = "{$server} ({$db}) (TRX#$id)"; - if ( isset( $this->mDBTrxHoldingLocks[$name] ) ) { + if ( isset( $this->dbTrxHoldingLocks[$name] ) ) { wfDebugLog( 'DBPerformance', "Nested transaction for '$name' - out of sync." ); } - $this->mDBTrxHoldingLocks[$name] = array( + $this->dbTrxHoldingLocks[$name] = array( 'start' => microtime( true ), 'conns' => array(), ); - $this->mDBTrxMethodTimes[$name] = array(); + $this->dbTrxMethodTimes[$name] = array(); - foreach ( $this->mDBTrxHoldingLocks as $name => &$info ) { + foreach ( $this->dbTrxHoldingLocks as $name => &$info ) { // Track all DBs in transactions for this transaction $info['conns'][$name] = 1; } @@ -73,7 +73,7 @@ class TransactionProfiler { * @param float $realtime Wall time ellapsed */ public function recordFunctionCompletion( $method, $realtime ) { - if ( !$this->mDBTrxHoldingLocks ) { + if ( !$this->dbTrxHoldingLocks ) { // Short-circuit return; // @todo hardcoded check is a tad janky @@ -83,10 +83,10 @@ class TransactionProfiler { } $now = microtime( true ); - foreach ( $this->mDBTrxHoldingLocks as $name => $info ) { + foreach ( $this->dbTrxHoldingLocks as $name => $info ) { // Hacky check to exclude entries from before the first TRX write if ( ( $now - $realtime ) >= $info['start'] ) { - $this->mDBTrxMethodTimes[$name][] = array( $method, $realtime ); + $this->dbTrxMethodTimes[$name][] = array( $method, $realtime ); } } } @@ -104,28 +104,28 @@ class TransactionProfiler { */ public function transactionWritingOut( $server, $db, $id ) { $name = "{$server} ({$db}) (TRX#$id)"; - if ( !isset( $this->mDBTrxMethodTimes[$name] ) ) { + if ( !isset( $this->dbTrxMethodTimes[$name] ) ) { wfDebugLog( 'DBPerformance', "Detected no transaction for '$name' - out of sync." ); return; } $slow = false; - foreach ( $this->mDBTrxMethodTimes[$name] as $info ) { + foreach ( $this->dbTrxMethodTimes[$name] as $info ) { $realtime = $info[1]; - if ( $realtime >= $this->mDBLockThreshold ) { + if ( $realtime >= $this->dbLockThreshold ) { $slow = true; break; } } if ( $slow ) { - $dbs = implode( ', ', array_keys( $this->mDBTrxHoldingLocks[$name]['conns'] ) ); + $dbs = implode( ', ', array_keys( $this->dbTrxHoldingLocks[$name]['conns'] ) ); $msg = "Sub-optimal transaction on DB(s) [{$dbs}]:\n"; - foreach ( $this->mDBTrxMethodTimes[$name] as $i => $info ) { + foreach ( $this->dbTrxMethodTimes[$name] as $i => $info ) { list( $method, $realtime ) = $info; $msg .= sprintf( "%d\t%.6f\t%s\n", $i, $realtime, $method ); } wfDebugLog( 'DBPerformance', $msg ); } - unset( $this->mDBTrxHoldingLocks[$name] ); - unset( $this->mDBTrxMethodTimes[$name] ); + unset( $this->dbTrxHoldingLocks[$name] ); + unset( $this->dbTrxMethodTimes[$name] ); } } -- 2.20.1